{% extends 'layout/manage.html' %}
{% block css %}
    <style>
        .padb {
            padding-bottom: 10px;
        }

        .project {
            margin-top: 10px;
        }

        .panel-body {
            padding: 0;
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: flex-start;
            flex-wrap: wrap;
        }

        .panel-body > .item {
            border-radius: 6px;
            width: 228px;
            border: 1px solid #dddddd;
            margin: 20px 10px;

        }

        .panel-body > .item:hover {
            border: 1px solid #f0ad4e;
        }

        .panel-body > .item > .title {
            height: 104px;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 15px;
            text-decoration: none;
        }

        .panel-body > .item > .info {
            padding: 10px 10px;

            display: flex;
            justify-content: space-between;

            border-bottom-left-radius: 6px;
            border-bottom-right-radius: 6px;
            color: #8c8c8c;

        }

        .panel-body > .item > .info a {
            text-decoration: none;
        }

        .panel-body > .item > .info .fa-star {
            font-size: 18px;
        }

        .color-radio label {
            margin-left: 0;
            padding-left: 0;
        }

        .color-radio input[type="radio"] {
            display: none;
        }

        .color-radio input[type="radio"] + .cycle {
            display: inline-block;
            height: 25px;
            width: 25px;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }

        .color-radio input[type="radio"]:checked + .cycle {
            border: 2px solid black;
        }

    </style>
{% endblock %}
{% block content %}
    <div class="container-fluid padb">
        <a href="" class="btn btn-primary" data-toggle="modal"
           data-target="#myModal"><i class="fa fa-plus"
                                     aria-hidden="true"></i>新建项目</a>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
         aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">新建项目</h4>
                </div>
                <div class="modal-body">
                    {#                    <form>#}
                    {#                        <div class="form-group">#}
                    {#                            <label for="exampleInputEmail1">项目名</label>#}
                    {#                            <input type="email" class="form-control"#}
                    {#                                   id="exampleInputEmail1" placeholder="Email">#}
                    {#                        </div>#}
                    {#                        <div class="form-group">#}
                    {#                            <label for="exampleInputPassword1">颜色</label>#}
                    {#                            <input type="password" class="form-control"#}
                    {#                                   id="exampleInputPassword1"#}
                    {#                                   placeholder="Password">#}
                    {#                        </div>#}
                    {#                         <div class="form-group">#}
                    {#                            <label for="exampleInputPassword1">描述信息</label>#}
                    {#                             <textarea name="" id="" cols="30"#}
                    {#                                       rows="10" class="form-control"></textarea>#}
                    {#                         </div>#}
                    {##}
                    {##}
                    {#                    </form>#}
                    <form action="" method="post" id="addForm">  <!--这个是form表单 用来添加项目的 -->
                        {% csrf_token %}
                        {% for i in form %}

                            <div class="form-group">
                                <label for="{{ i.id_for_label }}">{{ i.label }}</label>
                                {{ i }}
                                <span class="error-msg"></span>
                            </div>
                        {% endfor %}

                    </form>


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default"
                            data-dismiss="modal" id="btn1">关 闭
                    </button>
                    <button id="btnSubmit" type="button"
                            class="btn btn-primary">保 存
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="panel panel-danger">
        <div class="panel-heading"><i class="fa fa-star-o"
                                      aria-hidden="true"></i>星标项目
        </div>
        <div class="panel-body">
            {% for i in my_project_list.true %} <!--循环展示项目 根据不同的字段区别项目放在哪里 -->

                <div class="item">
                    <a href="{% url 'dashboard' i.value.0 %}" class="title"
                       style="background-color: orange;">{{ i.value.1 }}</a>
                    <div class="info">
                        <div>
                            <a href="{% url 'project_unstar' project_type=i.type project_id=i.value.0 %}">
                                <i class="fa fa-star" aria-hidden="true"
                                   style="color: #f0ad4e;"></i>
                            </a>
                            <span>{{ request.user_name }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ i.value.5 }}</span>
                        </div>
                    </div>
                </div>
            {% endfor %}

        </div>
    </div>


    <div class="panel panel-primary">
        <div class="panel-heading"><i class="fa fa-bars" aria-hidden="true"></i>我创建的
        </div>
        <div class="panel-body">
            {% for i in my_project_list.my %}
                {#                <div>{{ i }}</div>#}
                <div class="item">
                    <a href="{% url 'dashboard' i.0  %}" class="title"
                       style="background-color: orange;">{{ i.1 }}项目id{{ i.0 }}</a>
                    <div class="info">
                        <div>
                            <a href="{% url 'project_star' project_type='my' project_id=i.0 %}">
                                <i class="fa fa-star" aria-hidden="true"
                                   style="color: #d5d5d5"></i>
                                <!-- color: #f0ad4e-->
                            </a>
                            <span>{{ request.user_name }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ i.5 }}</span>
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    </div>
    <div class="panel panel-info">
        <div class="panel-heading"><i class="fa fa-hand-paper-o"></i>我参与的</div>
        <div class="panel-body">
            {% for i in my_project_list.join %}
                <div class="item">
                    <a href="{% url 'dashboard' i.0  %}" class="title"
                       style="background-color: orange;">{{ i.1 }}</a>
                    <div class="info">
                        <div>
                            <a href="{% url 'project_star' project_type='join' project_id=i.0 %}">
                                <i class="fa fa-star" aria-hidden="true"
                                   style="color: #d5d5d5"></i>
                                <!-- color: #f0ad4e-->
                            </a>
                            <span>{{ request.user_name }}</span>
                        </div>
                        <div>
                            <i class="fa fa-user-o" aria-hidden="true"></i>
                            <span>{{ i.5 }}</span>
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    </div>
    {#    {% load projected %}#}
    {#    {% all_project request %}#}
    
{% endblock %}

{% block js %}
    <script>
        $(function () {
            bindSubmit();
        });

        function bindSubmit() {
            $('#btnSubmit').click(function () {
                $.ajax({
                    url: '{% url 'project_list' %}',
                    type: 'post',
                    data: $('#addForm').serialize(),
                    dataType: 'JSON',
                    success: function (res) {
                        console.log(res);
                        if (res.status) {
                            alert(res.data);
                            location.href = location.href;
                        } else {
                            $.each(res.error, function (key, value) {
                                $('#id_' + key).next().text(value[0])
                            })
                        }
                    }
                })
            })
        }
    </script>
{% endblock %}